<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>

    function getTwoSumIndex(arr, target) {
      const targetMap = new Map();
      for (let i in arr) {
        const curDiff = target - arr[i]
        if (targetMap.has(curDiff)) {
          return [targetMap.get(curDiff), i]
        }
        targetMap.set(arr[i], i)
      }
      return []; // 如果没有找到符合条件的索引，返回 null
    }

    const numArr = [2, 7, 11, 15];
    const result = getTwoSumIndex(numArr, 9);
    console.log('result:', result); // [0, 1]
    

  </script>
</body>
</html>